package lambda.string;

import java.util.Arrays;

public class SplitDemo2 {
    public static void main(String[] args) {
        String str = "a=b=c=d=e=f======";
        String[] arr = str.split("=");
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
        //仅拆分出2项
        arr = str.split("=", 2);
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
        //仅拆分出3项
        arr = str.split("=", 3);
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
 /*
            当limit超过最多可拆分项时，保留最多可拆分项(包括原本可能舍弃的末尾的连续空字符串)
         */
        arr = str.split("=", 20);
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
        //limit=0时与split(String regex)效果相同
        arr = str.split("=", 0);
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
        //limit<0时，应拆尽拆
        arr = str.split("=", -1);
        System.out.println("arr.Len:" + arr.length);
        System.out.println(Arrays.toString(arr));
    }
}
